package com.techsoul.module.pms.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.log.annotation.Log;
import com.techsoul.common.log.enums.OperationTypeEnum;
import com.techsoul.module.pms.enmus.WmsOutStatusEnum;
import com.techsoul.module.pms.pojo.param.TWmsDeliveryPickupPlanSaveParam;
import com.techsoul.module.pms.pojo.param.TWmsDeliveryPickupPlanSearchParam;
import com.techsoul.module.pms.pojo.param.TWmsReciptIntoLocPlanSaveParam;
import com.techsoul.module.pms.pojo.param.TbWmsMaterialDeliveryLineSaveParam;
import com.techsoul.module.pms.service.ITWmsDeliveryPickupPlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;

/**
 * 拣货计划 Controller
 *
 * @author liuen
 * @date 2023-03-28
 */
@Api(tags = "拣货计划")
@RestController
@RequestMapping("/web/tWmsDeliveryPickupPlan")
public class TWmsDeliveryPickupPlanController {

    @Autowired
    private Result result;
    
    @Autowired
    private ITWmsDeliveryPickupPlanService service;

    @ApiOperation("新增")
    @Log(title = "拣货计划", operationType = OperationTypeEnum.INSERT)
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:insert')")
    @PostMapping
    public Result insert(@Valid @RequestBody TWmsDeliveryPickupPlanSaveParam params) {
        return result.success(this.service.insert(params));
    }
    @ApiOperation("新增")
    @Log(title = "拣货计划", operationType = OperationTypeEnum.GENPICKUP)
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:genPickupPlan')")
    @PostMapping("/genPickupPlan")
    public Result genPickupPlan() {
        return result.success(this.service.genPickupPlan());
    }

    @ApiOperation("抢单")
    @Log(title = "抢单", operationType = OperationTypeEnum.getJob)
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:getJob')")
    @GetMapping("/getPickUpJob/{id}")
    public Result getPickUpJob( @PathVariable String id) {
        return result.success(this.service.getPickUpJob(id));
    }
    @ApiOperation("新增")
    @Log(title = "拣货计划", operationType = OperationTypeEnum.GENPICKUP)
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:genPickupPlan')")
    @PostMapping("/genPickupPlanBySelectItem/{ids}")
    public Result genPickupPlanBySelectItem(@RequestBody TWmsDeliveryPickupPlanSaveParam params, @PathVariable String[] ids) {
        return result.success(this.service.genPickupPlanBySelectItem(params,ids));
    }

    @ApiOperation("拣货计划发布")
    @Log(title = "拣货计划发布", operationType = OperationTypeEnum.GENINLOC)
    //@PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:publish')")
    @PostMapping("/handlePublish")
    public Result handlePublish() {
        return result.success(this.service.handlePublish());
    }

    @ApiOperation("批量删除（多个用逗号隔开）")
    @Log(title = "拣货计划", operationType = OperationTypeEnum.DELETE)
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialDeliveryLine:delete')")
    @DeleteMapping("/{ids}")
    public Result batchDelete(@PathVariable String[] ids) {
        return result.success(this.service.batchDelete(Arrays.asList(ids)));
    }

    @ApiOperation("修改")
    @Log(title = "拣货计划", operationType = OperationTypeEnum.UPDATE)
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:update')")
    @PutMapping
    public Result update(@Valid @RequestBody TWmsDeliveryPickupPlanSaveParam params) {
        return result.success(this.service.update(params));
    }
    @ApiOperation("确认拣货")
    @PreAuthorize("hasAnyAuthority('web:tbWmsMaterialDeliveryLine:outbound')")
    @PostMapping("/pickUpAndOutbound")
    public Result pickUpAndOutbound(@Valid @RequestBody TWmsDeliveryPickupPlanSaveParam params) {

        params.setStatus(WmsOutStatusEnum.outed.getValue());
        return result.success(this.service.pickUpAndOutbound(params));
    }
    @ApiOperation("详情")
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:search')")
    @GetMapping("/{id}")
    public Result findById(@PathVariable("id") String id) {
        return result.success(this.service.findById(id));
    }

    @ApiOperation("列表")
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:search')")
    @PostMapping("/search")
    public Result findAll(@RequestBody TWmsDeliveryPickupPlanSearchParam params) {
        return result.success(this.service.findAll(params));
    }

    @ApiOperation("列表-分页")
    @PreAuthorize("hasAnyAuthority('web:tWmsDeliveryPickupPlan:search')")
    @PostMapping("/search/{current}/{pageSize}")
    public Result findAll(@RequestBody TWmsDeliveryPickupPlanSearchParam params, @PathVariable Integer current, @PathVariable Integer pageSize) {
        return result.success(this.service.findAll(params, current, pageSize));
    }

}
